想实现一个web版的搜索功能,一开始准备用flask和html交互,研究了后干脆使用elasticsearch的js版控件,省了许多事。


https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/browser-builds.html

Browser Buildsedit  
    We also provide builds of the elasticsearch.js > client for use in the browser.  
     These versions of the client are currently experimental. We test these builds  using saucelabs in Chrome, Firefox, and Internet Explorer 10, and 11.  
    While there is a way to get it working in IE 9, the browser severely limits what you can do with cross-domain requests. Because of these limits, many of the API calls and other functionality do not work.

直接下载v11.0.1的zip文件,选择其中的elasticsearch.js文件复制到main.js同目录下

官方文档没有给出如何使用,参考各种文章后直接
// elasticsearch.js 将 elasticsearch 命名空间加入窗口
var client = elasticsearch.Client({ … });
根据官方文档进行测试
Ping the clusteredit
Send a HEAD request to “/?hello=elasticsearch” and allow up to 30 seconds for it to complete.
client.ping({
requestTimeout: 30000,

  // undocumented params are appended to the query string
  hello: "elasticsearch"
}, function (error) {
  if (error) {
    console.error('elasticsearch cluster is down!');
  } else {
    console.log('All is well');
  }
});

Chrome下调出控制台,点击按钮看到ALL IS WELL